package cn.com.skbang.backend.user.feign.biz;


import cn.com.skbang.backend.common.service.BaseBiz;
import cn.com.skbang.backend.user.feign.interfaces.vo.TeacherViewVO;
import cn.hutool.core.collection.CollUtil;
import cn.com.skbang.backend.common.core.tools.BeanUtil;
import cn.com.skbang.backend.user.dao.TeacherDao;
import cn.com.skbang.backend.user.dao.impl.mapper.entity.Teacher;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import javax.validation.constraints.NotNull;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 讲师信息
 *
 * @author wujing
 */
@Component
@RequiredArgsConstructor
//TODO xupc FeignLectureBiz -> FeignTeacherBiz
public class FeignTeacherBiz extends BaseBiz {

    @NotNull
    private final TeacherDao dao;

    public TeacherViewVO getById(Long id) {
        Teacher record = dao.getById(id);
        return BeanUtil.copyProperties(record, TeacherViewVO.class);
    }

    public Map<Long, String> listByIds(List<Long> lecturerIdList) {
        List<Teacher> teacherList = dao.listByIds(lecturerIdList);
        if (CollUtil.isNotEmpty(teacherList)) {
            return teacherList.stream().collect(Collectors.toMap(Teacher::getId, Teacher::getTeacherName));
        }
        return new HashMap<>();
    }
}
